<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
</head>
<body>
<%@ page import="cs236369.hw5.InitListener" %>
<%@ page import="cs236369.hw5.DBConnection" %>
<%@ page import="cs236369.hw5.Team" %>
<%@ page import="cs236369.hw5.Post" %>
<%@ page import="cs236369.hw5.User" %>
<%@ page import="java.util.ArrayList" %>

<%
	String admin = (String)session.getAttribute("admin");
	if(admin == null) { // user is not an admin
		response.sendRedirect(request.getContextPath() + InitListener.welcomePage);
		return;
	}
	ArrayList<Post> teams = DBConnection.getAllTeams();
%>
<div class="text">
<p class="subtitle">Manage teams</p>
<p class="topic">click on an team name for more details</p>
<table id="adminTable" class="adminTable">
<tr class="title"><td>team id</td><td>team name</td><td>creator</td><td>position</td><td>delete</td></tr>
<%
	int row = 1;
	User user;
	Team team;
	for(Post post : teams) {
		team = (Team) post;
		out.print("<tr class=\"data\">");
		out.print("<td>" + team.getId() + "</td>");
		out.print("<td><label onclick=\"loadToMainContent(\'team.jsp?postId=" +
				post.getId() + "\')\">" + team.getName() + "</td>");
		user = DBConnection.getUserDetails(team.getOwner());
		out.print("<td>" + user.getFirstName() + " " + user.getLastName() + "</td>");
		out.print("<td>(" + team.getLatitute() + ", " + team.getLongitude() + ")</td>");
		out.println("<td><input type=\"button\" class=\"regularButton\" value=\"Delete\" id=\"delCell" + row +
				"\" onclick=\"delTeam(" + row + ", " + team.getId() + ")\"></input></td></tr>");
		row++;
	}
%>
</table></div>
</body>
</html>